﻿$(document).ready(function () {
   // $("input[id='" + ImageAttachementFieldControlID + "']").parent().parent().parent().hide();
    //$("input[id='" + ImageAttachementFieldControlID + "']").val('');

    $("input[id='" + ImageAttachementFieldControlID + "']").parent().hide();
    $("input[id='" + ImageAttachementFieldControlID + "']").val('');
    $("input[id='" + ImageAttachementFieldControlID + "']").parent().parent().append('HINT: Attach a picture to the list item, and flag it as (Default Picture) to appear in the picture field.');

});

function PreSaveAction() {
    var table = document.getElementById("idAttachmentsTable");
    var oRow = table.rows.length;
    hasPicture = false;
    for (var rowCounter = 0; rowCounter < oRow; rowCounter++) {
        if (navigator.appName == 'Microsoft Internet Explorer') {
            var fileName = table.rows[rowCounter].cells[2].innerText;
            var fileExtenssion = table.rows[rowCounter].cells[3].innerText.toLowerCase();
        }
        else {
            var fileName = table.rows[rowCounter].cells[2].textContent;
            var fileExtenssion = table.rows[rowCounter].cells[3].textContent.toLowerCase();
        }
        if (fileExtenssion == 'jpg' || fileExtenssion == 'jpeg' || fileExtenssion == 'bmp' || fileExtenssion == 'png' || fileExtenssion == 'gif' || fileExtenssion == 'jpe' || fileExtenssion == 'jfif') {
            hasPicture = true;
            if (table.rows[rowCounter].getElementsByTagName("input")[0].checked) {
                fileName = "http://" + fileName;
                $('input[id='+ImageAttachementFieldControlID+']').val(fileName);
                return true;
            }
        }
    }
    if (hasPicture) {
        alert("Please choose a picture to be your item default picture.");
        return false;
    }
    else {
        return true;
    }
}
function OkAttach() {
    ULS1Lu: ;
    fileID = FileuploadString + FileUploadIndex;
    fileInput = GetAttachElement(fileID);
    filename = TrimWhiteSpaces(fileInput.value);
    if (!filename) {
        var L_FileNameRequired_TXT = "You must specify a non-blank value for File Name.";
        alert(L_FileNameRequired_TXT);
        fileInput.focus();
    }
    else if (filename.indexOf('&') != -1 || filename.indexOf('%') != -1 || filename.indexOf('#') != -1 || filename.indexOf('~') != -1) {
        var L_FileNameRequired_TXT = "File Name can not contain any of these characters: ~&#%";
        alert(L_FileNameRequired_TXT);
        fileInput.focus();
    }
    else {
        var L_FileUploadToolTip_text = "Name";
        oRow = document.getElementById("idAttachmentsTable").insertRow(-1);
        RowID = 'attachRow' + FileUploadIndex;
        oRow.id = RowID;
        oCellFileName = oRow.insertCell(-1);
        oCellFileName.className = "ms-vb";
        oCellFileName.innerHTML = "<span dir=\"ltr\">" + filename + "</span>&nbsp;&nbsp;&nbsp;&nbsp;";
        oCellControl = oRow.insertCell(-1);
        oCellControl.className = "ms-propertysheet";
        oCellControl.innerHTML = "<IMG SRC='" + document.getElementsByName("RectGifUrl").item(0).value + "'>&nbsp;<a href='javascript:RemoveLocal(\"" + RowID + "\",\"" + fileID + "\")'>" + L_Delete_Text + "</a> ";

        var fileExtenssion = filename.split('.')[filename.split('.').length - 1].toLowerCase();
        var absoluteFileName = filename.split('\\')[filename.split('\\').length - 1];

        oCellAbsoluteFileName = oRow.insertCell(-1);
        oCellAbsoluteFileName.innerHTML = "<span style='position:absolute;top:0px;left:0px;visibility:hidden;'>" + absoluteFileName + "</span>";

        oCellFileExtension = oRow.insertCell(-1);
        oCellFileExtension.innerHTML = "<span style='position:absolute;top:0px;left:0px;visibility:hidden;'>" + fileExtenssion + "</span>";
        fileExtenssion = fileExtenssion.toLowerCase();
        if (fileExtenssion == 'jpg' || fileExtenssion == 'jpeg' || fileExtenssion == 'bmp' || fileExtenssion == 'png' || fileExtenssion == 'gif' || fileExtenssion == 'jpe' || fileExtenssion == 'jfif') {
            oCellRadioControl = oRow.insertCell(-1);
            oCellRadioControl.innerHTML = "&nbsp;<input type='radio' id='isDefault' name='group1'>Default Picture</input>"
        }

        fileInput.style.display = "none";
        ++FileUploadIndex;
        oAttachments = document.getElementById("attachmentsOnClient");
        var inputNode = document.createElement("input");
        inputNode.tabIndex = "1";
        inputNode.type = "File";
        inputNode.className = "ms-longfileinput";
        inputNode.title = L_FileUploadToolTip_text;
        inputNode.name = FileuploadString + FileUploadIndex;
        inputNode.id = FileuploadString + FileUploadIndex;
        inputNode.size = "56";
        oAttachments.appendChild(inputNode);
        var theForm = fileInput.form;
        theForm.encoding = 'multipart/form-data';
        document.getElementById("idAttachmentsRow").style.display = "";
        ShowPart1();
    }
}
		